package main

import (
	"flag"

	"gitee.com/thubcc/rtlmmap/web"
	"github.com/gin-gonic/gin"
)

var (
	argFc   = flag.String("f", "874.2e6", "LTE Center Freqency")
	argGain = flag.String("g", "40.0", "Rx Gain")
	argSr   = flag.String("s", "1.92e6", "Rx Gain")
)

func main() {
	flag.Parse()
	config := web.RFConfig{
		FreqCenter: web.Str1int(*argFc),
		SampleRate: web.Str1int(*argSr),
		Gain:       web.Str10int(*argGain),
	}
	ps := web.NewPorts(&config)
	r := router(ps)
	r.Run(":8080")
}

func router(ps *web.Ports) (r *gin.Engine) {
	r = gin.Default()
	r.GET("/list", ps.List)
	r.GET("/open/:port", ps.PortSpecificationAPI("Open"))
	r.GET("/suspend/:port", ps.PortSpecificationAPI("Suspend"))
	r.GET("/start/:port", ps.PortSpecificationAPI("Start"))
	r.GET("/resume/:port", ps.PortSpecificationAPI("Resume"))
	r.GET("/fc/:port", ps.PortSpecificationAPI("SetFc"))
	r.GET("/gain/:port", ps.PortSpecificationAPI("SetGain"))
	return
}
